<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/6/18 17:11
 */

namespace App\Project\Filters;

use Illuminate\Http\Request;
use Illuminate\Support\Arr;

class AuxiliaryFilter extends FilterAbstract
{
    protected $intResultKey = 'result_n';

    protected $intResult = [];

    protected $boolResultKey = 'result_b';

    protected $boolResult = [];

    protected $arrayResultKey = 'result_a';

    protected $arrayResult = [];

    public function __construct(Request $request)
    {
        parent::__construct($request);

        $this->arrayResult();
//        $this->boolResult();
        $this->intResult();
    }


    protected function forExtend()
    {
        //  OGTT    'blood.glu0', 'blood.glu2' 单位字段
        //  尿常规 'urine_routine.ld', 无  药敏结果	危急提示	备注 项
        $other = [
            'blood.glu0.unit',
            'blood.glu2.unit',
            'urine_routine.ld.result_n',
            'iconography.time',
        ];

        $map = [];

        foreach ([
                     'ogtt.glu.results_n',
                     'ogtt.ins.results_n',
                     'ogtt.c-p.results_n',
                 ] as $item) {

            $map[$item] = array_pad([], 5, 1);
        }

        //  array 结果
        foreach ($this->arrayResult as $item) {
            $map[$item . '.' . $this->arrayResultKey . '.'. $this->boolResultKey] = 1;
            $map[$item . '.' . $this->arrayResultKey . '.'. $this->intResultKey] = 1;
            $map[$item] = array_flip($this->commonForResult());
        }

        //  bool 结果
//        foreach ($this->boolResult as $item) {
//            $map[$item . '.' . $this->boolResultKey] = 1;
//            $map[$item] = array_flip($this->commonForResult());
//        }

        //  int 结果
        foreach ($this->intResult as $item) {
            $map[$item . '.' . $this->intResultKey] = 1;
            $map[$item] = array_flip($this->commonForResult());
        }

        return array_merge($map, array_flip($other));
    }

    protected function arrayResult()
    {
        $this->arrayResult = [
            'diabetes_antibody.ica',
            'diabetes_antibody.gad',
            'diabetes_antibody.ia2',
            'diabetes_antibody.iaa',
            'urine_routine.wbc',
            'urine_routine.pro',
            'urine_routine.glu',
            'urine_routine.ket',
            'urine_routine.bil',
            'urine_routine.bld',
        ];
    }

    protected function boolResult()
    {
        $this->boolResult = [];
    }

    protected function intResult()
    {
        $this->intResult = [
            'blood.glu0',
            'blood.glu2',
            'insulin.ins0',
            'insulin.ins120',
            'peptide_c.c-p0',
            'peptide_c.c-p120',
            'saccharify.hba1c',
            'saccharify.ga%',
            'acr.acr',
            'uaer.8hu-v',
            'uaer.uma1b',
            'uaer.uae',
            'urine_routine.sg',
            'urine_routine.ph',
            'urine_routine.ubg',
            'biochemical_examination.alt',
            'biochemical_examination.tp',
            'biochemical_examination.alb',
            'biochemical_examination.a/g',
            'biochemical_examination.tbil',
            'biochemical_examination.dbil',
            'biochemical_examination.ggt',
            'biochemical_examination.alp',
            'biochemical_examination.ast',
            'biochemical_examination.tba',
            'biochemical_examination.ld',
            'biochemical_examination.che',
            'biochemical_examination.k',
            'biochemical_examination.na',
            'biochemical_examination.cl',
            'biochemical_examination.tco2',
            'biochemical_examination.ca',
            'biochemical_examination.cr(e)',
            'biochemical_examination.urea',
            'biochemical_examination.glu',
            'biochemical_examination.ua',
            'biochemical_examination.p',
            'biochemical_examination.tc',
            'biochemical_examination.tg',
            'biochemical_examination.hdl-c',
            'biochemical_examination.ldl-c',
            'biochemical_examination.apoa1',
            'biochemical_examination.apob',
            'biochemical_examination.lp(a)',
            'biochemical_examination.hscrp',
            'biochemical_examination.ffa',
            'biochemical_examination.pa',
            'liver_function.alt',
            'liver_function.alb',
            'liver_function.tbil',
            'liver_function.dbil',
            'liver_function.alp',
            'liver_function.ast',
            'liver_function.ld',
            'kidney.k',
            'kidney.na',
            'kidney.cl',
            'kidney.tco2',
            'kidney.ca',
            'kidney.cr(e)',
            'kidney.urea',
            'kidney.glu',
            'kidney.ua',
            'kidney.p',
            'kidney.egfr',
            'electrolyte.k',
            'electrolyte.na',
            'electrolyte.cl',
            'electrolyte.tco2',
            'electrolyte.ca',
            'tg_chohdlldl.tc',
            'tg_chohdlldl.tg',
            'tg_chohdlldl.hdl-c',
            'tg_chohdlldl.ldl-c',
            'bt_paba.amy',
            'bt_paba.lip',
            'thyroid_function_one.ft3',
            'thyroid_function_one.ft4',
            'thyroid_function_one.tsh3',
            'thyroid_function_two.ft3',
            'thyroid_function_two.ft4',
            'thyroid_function_two.t3',
            'thyroid_function_two.t4',
            'thyroid_function_two.dbil',
            'thyroid_function_two.tsh3',
            'thyroid_function_three.a-tg',
            'thyroid_function_three.a-tpo',
            'plasma_acth.acth(0am)',
            'plasma_acth.acth(8am)',
            'plasma_acth.acth(4pm)',
            'blood_cortisol.f(0am)',
            'blood_cortisol.f(8am)',
            'blood_cortisol.f(4pm)',
            'blood_cortisol.f',
            'endocrine_examination.lh',
            'endocrine_examination.fsh',
            'endocrine_examination.e2',
            'endocrine_examination.p',
            'endocrine_examination.t',
            'endocrine_examination.prl',
            'growth_hormone.gh',
            'insulin_growth_factor.igf1',
            'blood_routine.wbc',
            'blood_routine.ly%',
            'blood_routine.mono%',
            'blood_routine.neut%',
            'blood_routine.eos%',
            'blood_routine.baso%',
            'blood_routine.luc%',
            'blood_routine.ly#',
            'blood_routine.mono#',
            'blood_routine.neut#',
            'blood_routine.eos#',
            'blood_routine.baso#',
            'blood_routine.rbc',
            'blood_routine.hgb',
            'blood_routine.hct',
            'blood_routine.mcv',
            'blood_routine.mchc',
            'blood_routine.mch',
            'blood_routine.chcm',
            'blood_routine.ch',
            'blood_routine.rdw',
            'blood_routine.hdw',
            'blood_routine.plt',
            'blood_routine.pct',
            'blood_routine.pdw',
            'blood_routine.mpv',
            'blood_gas_analysis.ph',
            'blood_gas_analysis.lac',
            'blood_gas_analysis.hco3_',
            'blood_gas_analysis.po2',
            'blood_gas_analysis.pco2',
            'blood_coagulation_two.pt',
            'blood_coagulation_two.pt%',
            'blood_coagulation_two.inr',
            'blood_coagulation_two.fbg',
            'blood_coagulation_two.aptt',
            'blood_coagulation_two.aptt-r',
            'blood_coagulation_two.tt',
            'blood_coagulation_two.d-dimer',
            'dexamethasone_suppression.24hufc(d1)',
            'dexamethasone_suppression.24hufc(d2)',
            'dexamethasone_suppression.24hufc(d4)',
            'dexamethasone_suppression.24hufc(d6)',
            'hydroxyvitamin.25oho2',
            'hydroxyvitamin.t-25ohd',
            'hydroxyvitamin.25ohd3',
            'uca_up.24hu-v',
            'uca_up.u-ca',
            'uca_up.u-p',
            'uca_up.24huca',
            'uca_up.24hup',
            'collagen_degradation.β-ctx',
        ];
    }

    protected function commonForResult()
    {
        return ['allergy', 'critical', 'remark'];
    }

    protected function getRootFieldsHasNoSon()
    {
        return [
            'id', 'record_id', 'blood','insulin','peptide_c','ogtt','saccharify','diabetes_antibody','acr','uaer',
            'urine_routine','biochemical_examination','liver_function','kidney','electrolyte','tg_chohdlldl',
            'bt_paba','thyroid_function_one','thyroid_function_two','thyroid_function_three','plasma_acth','blood_cortisol',
            'endocrine_examination','growth_hormone','insulin_growth_factor','blood_routine','blood_gas_analysis',
            'blood_coagulation_two','dexamethasone_suppression','hydroxyvitamin','uca_up','collagen_degradation',
            'iconography','remark',
        ];
    }

    protected function getRootFieldsHasSon()
    {
        return [
            'blood',
            'insulin',
            'peptide_c',
            'ogtt',
            'saccharify',
            'diabetes_antibody',
            'acr',
            'uaer',
            'urine_routine',
            'biochemical_examination',
            'liver_function',
            'kidney',
            'electrolyte',
            'tg_chohdlldl',
            'bt_paba',
            'thyroid_function_one',
            'thyroid_function_two',
            'thyroid_function_three',
            'plasma_acth',
            'blood_cortisol',
            'endocrine_examination',
            'growth_hormone',
            'insulin_growth_factor',
            'blood_routine',
            'blood_gas_analysis',
            'blood_coagulation_two',
            'dexamethasone_suppression',
            'hydroxyvitamin',
            'uca_up',
            'collagen_degradation',
        ];
    }

    protected function getSonFieldsForEachRoot()
    {
        return ['time', 'site', 'print',];
    }
}